package com.party.web.redisPubSub.publish;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.jedis.JedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;

/**
 * @Description: RedisMsgPublish
 * @Author: yangshoukun
 * @Date: 2018/4/2 20:11
 */
@Component
public class RedisMsgPublish {
    @Autowired
    private JedisConnectionFactory connectionFactory;

    public void publish(final String channel, final String message) {
        JedisConnection connection = connectionFactory.getConnection();
        Jedis jedis = connection.getNativeConnection();
        jedis.publish(channel, message);
        connection.close();
    }
}
